﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Jayden.Dll.Web.Enums;

namespace Jayden.Dll.Web.Styles
{
	public class CssElementCollection : IEnumerable<CssElement>
	{
		private List<CssElement> m_Elements = new List<CssElement>();

		public CssElement NewElement(params string[] selectors)
		{
			CssElement newElement = new CssElement(selectors);
			m_Elements.Add(newElement);
			return newElement;
		}

		public void AddElement(CssElement e) { m_Elements.Add(e); }


		public virtual void Render(TextWriter writer, RenderMode mode, int indentation)
		{
			foreach (CssElement element in m_Elements)
				element.Render(writer, mode, indentation);
		}

		public int CheckValidity()
		{
			int version = 0;
			foreach (CssElement element in m_Elements)
				version = Math.Max(version, element.CheckValidity());
			return version;
		}

		public IEnumerator<CssElement> GetEnumerator() { return m_Elements.GetEnumerator(); }
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return m_Elements.GetEnumerator(); }
	}
}
